"""
# -*- coding: utf-8 -*-
# @Time    : 2023/5/31 17:00
# @Author  : 王摇摆
# @FileName: Visual.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
import numpy as np
import matplotlib.pyplot as plt

from LR.EXP1.Cost import calcCost
from LR.EXP3.Data import X, y, start, end, W

plt.rcParams['font.sans-serif'] = ['microsoft yahei']  # 选择一个本地的支持中文的字体
fig, ax = plt.subplots()
ax.set_facecolor('#f8f9fa')

x1 = X[:][:, 0]
y1 = y
ax.scatter(x1, y1, marker='o', s=20, c='#e63946')
x2 = np.linspace(start, end, 100)
y2 = W[0] * x2
ax.plot(x2, y2, '#457b9d', label='W: %f, Cost: %f' % (W[0], calcCost(X, y, W)))
for i in range(len(x1)):
    ax.plot(np.linspace(x1[i], x1[i], 100), np.linspace(y1[i], W[0] * x1[i], 100), '#219ebc', linestyle='--')
ax.set_title('线性回归', color='#264653')
ax.set_xlabel('X', color='#264653')
ax.set_ylabel('Y', color='#264653')
ax.tick_params(labelcolor='#264653')
plt.legend(loc="upper left")
plt.show()
